﻿#include <QIcon>
#include <QMessageBox>
#include <QProgressDialog>
#include <QBrush>
#include <QColor>

#include "PoundListPrint.h"
#include "CLogOper.h"
#include "cpublicdataex.h"
#include "CSqlOperPub.h"

//按出厂时间倒序
bool sortReocrd(SRecordData stRecordA, SRecordData stRecordB)
{
	QDateTime qLeaveTimeA = QDateTime::fromString(stRecordA.sLeaveTime, "yyyy-MM-dd hh:mm:ss");
	QDateTime qLeaveTimeB = QDateTime::fromString(stRecordB.sLeaveTime, "yyyy-MM-dd hh:mm:ss");

	// 倒序排序
	return qLeaveTimeA > qLeaveTimeB;
}

PoundListPrint::PoundListPrint(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	initUI();
	initData();
	initTableView();
	initPrintDLL();
}

PoundListPrint::~PoundListPrint()
{}

/**
* @brief showEvent 页面显示时触发
* @param event 页面显示事件对象
*/
void PoundListPrint::showEvent(QShowEvent * event)
{
	// 创建进度框
	QProgressDialog progressDialog;
	progressDialog.setAutoClose(true);
	progressDialog.setLabelText(QString::fromLocal8Bit("程序初始化中..."));
	progressDialog.setRange(0, 0);  // 设置为不确定状态
	progressDialog.setModal(true);   // 设置为模态
	progressDialog.setCancelButton(nullptr); // 隐藏取消按钮
	progressDialog.setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
	progressDialog.setWindowTitle(QString::fromLocal8Bit("灰车辅料车手动打印磅单程序"));
	progressDialog.setWindowIcon(QIcon(":/PoundListPrint/app.ico"));
	progressDialog.resize(200, 50);

	// 显示进度框
	progressDialog.show();

	//等待三秒初始化
	QEventLoop loop;
	QTimer::singleShot(3000, &loop, SLOT(quit()));
	loop.exec();

	//关闭
	progressDialog.close();

	//加载默认数据
	loadData();
}

//初始化打印模块
void PoundListPrint::initPrintDLL()
{
	m_bPrintDLL = false;
	//驱动路径
	QString strDir = QApplication::applicationDirPath();
	QString sDllDir = strDir + "/PrintDLL/PrinterTabel.dll";

	QLibrary RfidControl(sDllDir);
	if (RfidControl.load())
	{
		m_lpPrintLabel = (lpPrintLabel)RfidControl.resolve("PrintLabel");
		m_lpSetPrintConfig = (lpSetPrintConfig)RfidControl.resolve("SetPrintConfig");

		SExecLog logInfo;
		logInfo.m_nAlarmLevel = enLogTypeRun;
		logInfo.m_sObject = QString::fromLocal8Bit("打印模块");
		logInfo.m_sLogDesc = QString::fromLocal8Bit("加载打印机驱动成功!");
		CLogOper::instance().addLogMsg("MainWindow", logInfo);
		m_bPrintDLL = true;
	}
	else
	{
		SExecLog logInfo;
		logInfo.m_nAlarmLevel = enLogTypeError;
		logInfo.m_sObject = QString::fromLocal8Bit("打印模块");
		logInfo.m_sLogDesc = QString::fromLocal8Bit("加载打印机驱动失败!请检查无误后重启程序!");
		CLogOper::instance().addLogMsg("MainWindow", logInfo);
		m_bPrintDLL = false;
	}

	//读取打印配置
	QString sIniDir = strDir + "/PrintDLL/PrinterTabel.ini";
	QSettings configIniRead(sIniDir, QSettings::IniFormat);
	configIniRead.setIniCodec(QTextCodec::codecForName("GB 2312"));
	m_sPrintTitle = configIniRead.value("main/Title", QString::fromLocal8Bit("过磅单")).toString();
	m_nPrintNum = (int)configIniRead.value("main/PrintNum", "1").toInt();
}

void PoundListPrint::initUI()
{
	setWindowTitle(QString::fromLocal8Bit("灰车辅料车手动打印磅单程序"));
	setWindowIcon(QIcon(":/PoundListPrint/app.ico"));
	resize(1600, 800);
	setStyleSheetFile();
	/*页面相关设置*/
	ui.dateTimeEditStartTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
	ui.dateTimeEditEndTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
	ui.lineEditCarOrCargoCode->setPlaceholderText(QString::fromLocal8Bit("不限"));
	ui.lineEditViewCardCode->setPlaceholderText(QString::fromLocal8Bit("不限"));
	ui.pushButtonSelect->setFocus();
	connect(ui.pushButtonSelect, &QPushButton::clicked, this, &PoundListPrint::slotSelectRecord);
	ui.comboBox->addItem(QString::fromLocal8Bit("入厂时间"), 0);
	ui.comboBox->addItem(QString::fromLocal8Bit("出厂时间"), 1);
}

void PoundListPrint::initData()
{
	//QDate qToday = QDate::currentDate();
	QDate qToday(2020, 3, 27);
	m_nTimeType = 0;
	m_qStartTime = QDateTime(qToday, QTime(0, 0, 0));
	ui.dateTimeEditStartTime->setDateTime(m_qStartTime);
	m_qEndTime = QDateTime(qToday, QTime(23, 59, 59));
	ui.dateTimeEditEndTime->setDateTime(m_qEndTime);
	m_sCarOrCargoCode = "";
	m_sViewCardCode = "";

	QString sExePath = QCoreApplication::applicationDirPath();
	//=================初始化日志=================
	LogModule* pLogModule = new LogModule(QString::fromLocal8Bit("日志"), "", this);
	//读取日志qss配置文件
	QString sLogQssConfig = "";//日志的qss配置
	QString sQssLogPath = sExePath;//qss路径
	sQssLogPath += "/qssStyle/LogModuleQss.txt";
	QFile file(sQssLogPath);// 创建QFile对象
	if (file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		// 创建QTextStream对象从文件中读取数据
		QTextStream inText(&file);
		while (!inText.atEnd())
		{
			sLogQssConfig += inText.readLine();
		}

		// 关闭文件
		file.close();
	}
	if (sLogQssConfig.size() > 0)
	{
		pLogModule->setQStyleSheet(sLogQssConfig);
	}

	CLogOper::instance().addLogModule("MainWindow", pLogModule);//将此日志控件交给日志单例类管理

	QGridLayout* pGridLayout = new QGridLayout();
	pGridLayout->setContentsMargins(0, 0, 0, 0);
	ui.widgetLog->setLayout(pGridLayout);
	pGridLayout->addWidget(pLogModule);

	{
		SExecLog logInfo;
		logInfo.m_nAlarmLevel = enLogTypeRun;
		logInfo.m_sObject = QString::fromLocal8Bit("系统");
		logInfo.m_sLogDesc = QString::fromLocal8Bit("日志初始化完成");
		CLogOper::instance().addLogMsg("MainWindow", logInfo);

	}

	//=================初始化读取ini配置文件和数据库=================
	if (CPublicDataEx::instance().initSql())
	{
		SExecLog logInfo;
		logInfo.m_nAlarmLevel = enLogTypeRun;
		logInfo.m_sObject = QString::fromLocal8Bit("数据库");
		logInfo.m_sLogDesc = QString::fromLocal8Bit("数据库初始化成功");
		CLogOper::instance().addLogMsg("MainWindow", logInfo);
	}
	else
	{
		SExecLog logInfo;
		logInfo.m_nAlarmLevel = enLogTypeError;
		logInfo.m_sObject = QString::fromLocal8Bit("数据库");
		logInfo.m_sLogDesc = QString::fromLocal8Bit("数据库初始化失败");
		CLogOper::instance().addLogMsg("MainWindow", logInfo);

		return;
	}
}

void PoundListPrint::initTableView()
{
	m_pTableView = new QMyTableView();
	QGridLayout* pGridLayout = new QGridLayout();
	pGridLayout->setContentsMargins(0, 0, 0, 0);
	ui.widgetTableView->setLayout(pGridLayout);
	pGridLayout->addWidget(m_pTableView);
	QStringList listHeaderName;
	listHeaderName << QString::fromLocal8Bit("记录ID") << QString::fromLocal8Bit("车牌号") << QString::fromLocal8Bit("供应商")
		<< QString::fromLocal8Bit("进厂时间") << QString::fromLocal8Bit("出厂时间") << QString::fromLocal8Bit("毛重(吨)")
		<< QString::fromLocal8Bit("皮重(吨)") << QString::fromLocal8Bit("净重(吨)") << QString::fromLocal8Bit("是否已打印")
		<< QString::fromLocal8Bit("操作");
	//设置列数
	m_pTableView->m_pModel->setColumnCount(listHeaderName.count());
	//设置表头
	m_pTableView->m_pModel->setHorizontalHeaderLabels(listHeaderName);
	connect(m_pTableView->ui.tableView, &QTableView::doubleClicked, this, &PoundListPrint::slotGetSelectedRow);
}

//刷新表格UI
void PoundListPrint::refreshTableViewUI()
{
	int nWidth = ui.widgetTableView->width();
	int nItemWidth = nWidth / 10;
	QList<quint16> listColumnWidth;		//列宽
	listColumnWidth << nItemWidth * 0.9 << nItemWidth * 0.7 << nItemWidth * 2.6 << nItemWidth * 1.2 << nItemWidth * 1.2 << nItemWidth * 0.7
		<< nItemWidth * 0.7 << nItemWidth * 0.7 << nItemWidth * 0.6 << nItemWidth * 0.3;
	QList<quint16> listColumnHidden;	//隐藏列
	m_pTableView->ui.tableView->setModel(m_pTableView->m_pModel);

	//设置列宽
	for (int i = 0; i < listColumnWidth.count(); i++)
	{
		m_pTableView->ui.tableView->setColumnWidth(i, listColumnWidth.at(i));
	}
	//隐藏列
	if (0 < listColumnHidden.count())
	{
		for (quint16 i = 0; i < listColumnHidden.count(); i++)
		{
			m_pTableView->ui.tableView->hideColumn(listColumnHidden.at(i));
		}
	}
}

/**
* @brief slotGetSelectedRow 获得选中行号
* @param
*/
void PoundListPrint::slotGetSelectedRow(const QModelIndex & index)
{
	int nRow = index.row();

	// 获取选中行的数据
	QString sRecordId = index.sibling(nRow, 0).data().toString();

	SRecordData stRecordData = m_mapRecordData.value(sRecordId);
	//供应商不可打印
	if (!stRecordData.bToPrint)
	{
		return;
	}

	QString sTips = QString::fromLocal8Bit("是否打印该记录?");
	int nRet = messageBox(3, sTips);
	if (QMessageBox::Yes == nRet)
	{
		//打印
		printRecord(sRecordId);
	}
}

//设置样式文件
void PoundListPrint::setStyleSheetFile()
{
	QString sExePath = QCoreApplication::applicationDirPath();//
	QString sQssPath = sExePath + "/qssStyle/styleSheet.css";
	//QString sQssPath = sExePath + "/qssStyle/flatwhite.css";
	QFile qss(sQssPath);
	qss.open(QFile::ReadOnly);
	setStyleSheet(qss.readAll());
}

//加载数据
void PoundListPrint::loadData()
{
	//从数据库获取数据
	bool bRet = getRecordData();
	if (!bRet)
	{
		ui.labelErrTips->setText(QString::fromLocal8Bit("数据库执行出错!请检查数据库连接状态!"));
		ui.stackedWidget->setCurrentIndex(1);
		return;
	}

	int nDataSize = m_mapRecordData.size();

	//未查询到数据 切换显示
	if (0 == nDataSize)
	{
		ui.labelErrTips->setText(QString::fromLocal8Bit("未查询到指定条件下的记录!请变更查询条件后再试!"));
		ui.stackedWidget->setCurrentIndex(1);
	}
	//显示列表
	else
	{
		ui.stackedWidget->setCurrentIndex(0);
	}

	//对数据 按出厂时间排序
	QList<SRecordData> listRecordData = m_mapRecordData.values();
	qSort(listRecordData.begin(), listRecordData.end(), sortReocrd);

	//清空
	m_pTableView->m_pModel->removeRows(0, m_pTableView->m_pModel->rowCount());
	int nCount = nDataSize;
	m_pTableView->UpdateStatus(nCount);
	int nIndex = 0;
	for (int i = 0;i < listRecordData.size();i++)
	{
		SRecordData stRecordData = listRecordData.at(i);
		QList<QStandardItem*> item;
		item.append(new QStandardItem(stRecordData.sRecordId));
		item.append(new QStandardItem(stRecordData.sCarCode));
		item.append(new QStandardItem(stRecordData.sVendor));
		item.append(new QStandardItem(stRecordData.sRecordTime));
		item.append(new QStandardItem(stRecordData.sLeaveTime));
		item.append(new QStandardItem(QString::number(stRecordData.dMZQTY)));
		item.append(new QStandardItem(QString::number(stRecordData.dPZQTY)));
		item.append(new QStandardItem(QString::number(stRecordData.dNETQTY)));

		//是否已打印
		if (stRecordData.bIsPrint)
		{
			item.append(new QStandardItem(QString::fromLocal8Bit("是")));
		}
		else
		{
			item.append(new QStandardItem(QString::fromLocal8Bit("否")));
		}

		//供应商或料种是否可打印
		bool bToPrint = !stRecordData.bToPrint;
		//是否已经打印
		bool bIsPrint = !stRecordData.bIsPrint;

		//设置居中显示
		for (int nRow = 0; nRow < item.count(); nRow++)
		{
			item.at(nRow)->setTextAlignment(Qt::AlignCenter);
			
			//设置供应商不可打印
			if (bToPrint)
			{
				QBrush brush(QColor(170, 170, 170)); // 灰色
				item.at(nRow)->setBackground(brush);
				item.at(nRow)->setFlags(item.at(nRow)->flags() & ~Qt::ItemIsSelectable & ~Qt::ItemIsEditable);
			}
		}
		//设置已经打印
		if (bIsPrint)
		{
			QBrush brush(QColor(170, 170, 170)); // 灰色
			item.at(8)->setBackground(brush);
			item.at(8)->setForeground(QBrush(QColor(255, 255, 255)));
		}
		else
		{
			QBrush brush(QColor(60, 179, 113)); // 绿色
			item.at(8)->setBackground(brush);
			item.at(8)->setForeground(QBrush(QColor(255, 255, 255)));
		}

		m_pTableView->m_pModel->insertRow(m_pTableView->m_pModel->rowCount(), item);

		//添加操作按钮
		QPushButton* pOperBtn = new QPushButton(QString::fromLocal8Bit("打印"));
		pOperBtn->setProperty("recordId", stRecordData.sRecordId);
		connect(pOperBtn, SIGNAL(clicked()), this, SLOT(slotPrintPoundList()));

		//设置供应商打印按钮为不可选中
		if (bToPrint)
		{
			pOperBtn->setDisabled(true);
		}

		m_pTableView->ui.tableView->setIndexWidget(m_pTableView->m_pModel->index(nIndex, 9), pOperBtn);
		nIndex++;
	}

	refreshTableViewUI();
}

//错误判断
bool PoundListPrint::judgeError()
{
	//起始时间大于结束时间
	if (m_qEndTime < m_qStartTime)
	{
		messageBox(1, QString::fromLocal8Bit("起始时间不能大于结束时间!"));
		return false;
	}

	//跨度不超过一个月
	if (qAbs(m_qStartTime.daysTo(m_qEndTime)) > 30)
	{
		messageBox(1, QString::fromLocal8Bit("时间跨度不能超过30天!"));
		return false;
	}

	return true;
}

//从数据库获取记录数据
bool PoundListPrint::getRecordData()
{
	QString sErrMsg = "";
	QVector<QSqlRecord> vecRecord;
	bool bRet = false;
	/*车牌号和货票号判断 车牌号长度小于10*/
	//车牌号
	if (m_sCarOrCargoCode.size() < 10)
	{
		bRet = CSqlOperPub::instance().selCdRlRecMstqyInfo(vecRecord, m_nTimeType, m_qStartTime.toString("yyyy-MM-dd hh:mm:ss"),
			m_qEndTime.toString("yyyy-MM-dd hh:mm:ss"), m_sCarOrCargoCode, "", m_sViewCardCode, sErrMsg);
	}
	//货票号
	else
	{
		bRet = CSqlOperPub::instance().selCdRlRecMstqyInfo(vecRecord, m_nTimeType, m_qStartTime.toString("yyyy-MM-dd hh:mm:ss"),
			m_qEndTime.toString("yyyy-MM-dd hh:mm:ss"), "", m_sCarOrCargoCode, m_sViewCardCode, sErrMsg);
	}

	//查询出错
	if (!bRet)
	{
		QString sErrTips = QString::fromLocal8Bit("执行数据库操作时失败! 错误原因: ") + sErrMsg;
		messageBox(1, sErrTips);
		return false;
	}

	//保存数据
	m_mapRecordData.clear();  //清空
	for (int i = 0; i < vecRecord.size(); i++)
	{
		SRecordData stRecordData;
		stRecordData.sRecordId = vecRecord[i].value("RECORD_NO").toString();
		stRecordData.sTickNo = vecRecord[i].value("TICK_NO").toString();
		stRecordData.sCarCode = vecRecord[i].value("CAR_ID").toString();
		stRecordData.sVendor = vecRecord[i].value("VEN_NAME").toString();
		stRecordData.sCarrierName = vecRecord[i].value("CARRIER_NAME").toString();
		QString sToPrint = vecRecord[i].value("TOPRINT").toString();
		if ("Y" == sToPrint)
		{
			stRecordData.bToPrint = true;
		}
		else
		{
			stRecordData.bToPrint = false;
		}
		stRecordData.sRecordTime = vecRecord[i].value("RECORD_DTM").toDateTime().toString("yyyy-MM-dd hh:mm:ss");
		stRecordData.sLeaveTime = vecRecord[i].value("LEAVE_DTM").toDateTime().toString("yyyy-MM-dd hh:mm:ss");
		stRecordData.sCZTime = vecRecord[i].value("CZ_DTM").toDateTime().toString("yyyy-MM-dd hh:mm:ss");
		stRecordData.sJQTime = vecRecord[i].value("JQ_DTM").toDateTime().toString("yyyy-MM-dd hh:mm:ss");
		stRecordData.sViewCard = vecRecord[i].value("CARD_ID").toString().right(5);
		int nASHType = vecRecord[i].value("ASH_TYPE").toInt();
		if (1 == nASHType)
		{
			stRecordData.sASHType = QString::fromLocal8Bit("粗灰");
		}
		else if(2 == nASHType)
		{
			stRecordData.sASHType = QString::fromLocal8Bit("细灰");
		}
		else if(3 == nASHType)
		{
			stRecordData.sASHType = QString::fromLocal8Bit("原灰");
		}
		stRecordData.dMZQTY = vecRecord[i].value("MZ_QTY").toDouble();
		stRecordData.dPZQTY = vecRecord[i].value("PZ_QTY").toDouble();
		stRecordData.dNETQTY = vecRecord[i].value("NET_QTY").toDouble();

		//是否已经打印
		QString sIsPrint = vecRecord[i].value("ISPRINT").toString();
		if ("Y" == sIsPrint)
		{
			stRecordData.bIsPrint = true;
		}
		else
		{
			stRecordData.bIsPrint = false;
		}

		m_mapRecordData.insert(stRecordData.sRecordId, stRecordData);
	}

	return bRet;
}

//创建打印格式
void PoundListPrint::createPrintFormat(QList<QStringList>& dlistToPrint, SRecordData stRecordData)
{
	/*货票号*/
	QStringList sListTickNo;
	sListTickNo.push_back(QString::fromLocal8Bit("货票号"));
	sListTickNo.push_back(stRecordData.sTickNo);
	dlistToPrint.push_back(sListTickNo);
	/*称重时间*/
	QStringList sListRecordTime;
	sListRecordTime.push_back(QString::fromLocal8Bit("称重时间"));
	sListRecordTime.push_back(stRecordData.sCZTime);
	dlistToPrint.push_back(sListRecordTime);
	/*回皮时间*/
	QStringList sListLeaveTime;
	sListLeaveTime.push_back(QString::fromLocal8Bit("回皮时间"));
	sListLeaveTime.push_back(stRecordData.sJQTime);
	dlistToPrint.push_back(sListLeaveTime);
	/*供货单位*/
	QStringList sListVendor;
	sListVendor.push_back(QString::fromLocal8Bit("供货单位"));
	sListVendor.push_back(stRecordData.sCarrierName);
	dlistToPrint.push_back(sListVendor);
	/*品种*/
	QStringList sListASHType;
	sListASHType.push_back(QString::fromLocal8Bit("品种"));
	sListASHType.push_back(stRecordData.sASHType);
	dlistToPrint.push_back(sListASHType);
	/*车牌号*/
	QStringList sListCarCode;
	sListCarCode.push_back(QString::fromLocal8Bit("车牌号"));
	sListCarCode.push_back(stRecordData.sCarCode);
	dlistToPrint.push_back(sListCarCode);
	/*毛重*/
	QStringList sListMZQTY;
	sListMZQTY.push_back(QString::fromLocal8Bit("毛重(吨)"));
	sListMZQTY.push_back(QString::number(stRecordData.dMZQTY));
	dlistToPrint.push_back(sListMZQTY);
	/*皮重*/
	QStringList sListPZQTY;
	sListPZQTY.push_back(QString::fromLocal8Bit("皮重(吨)"));
	sListPZQTY.push_back(QString::number(stRecordData.dPZQTY));
	dlistToPrint.push_back(sListPZQTY);
	/*净重*/
	QStringList sListNETQTY;
	sListNETQTY.push_back(QString::fromLocal8Bit("净重(吨)"));
	sListNETQTY.push_back(QString::number(stRecordData.dNETQTY));
	dlistToPrint.push_back(sListNETQTY);
	/*卡号*/
	QStringList sListViewCard;
	sListViewCard.push_back(QString::fromLocal8Bit("卡号"));
	sListViewCard.push_back(stRecordData.sViewCard);
	dlistToPrint.push_back(sListViewCard);
	/*负责人*/
	QStringList sListRP;
	sListRP.push_back(QString::fromLocal8Bit("负责人"));
	sListRP.push_back("");
	dlistToPrint.push_back(sListRP);
	/*司磅员*/
	QStringList sListWM;
	sListWM.push_back(QString::fromLocal8Bit("司磅员"));
	sListWM.push_back("");
	dlistToPrint.push_back(sListWM);
	/*保管员*/
	QStringList sListBM;
	sListBM.push_back(QString::fromLocal8Bit("保管员"));
	sListBM.push_back("");
	dlistToPrint.push_back(sListBM);
	/*开票员*/
	QStringList sListBC;
	sListBC.push_back(QString::fromLocal8Bit("开票员"));
	sListBC.push_back("");
	dlistToPrint.push_back(sListBC);
}

//打印记录数据
void PoundListPrint::printRecord(QString sRecordId)
{
	//驱动未加载成功
	if (!m_bPrintDLL)
	{
		QString sErrTips = QString::fromLocal8Bit("打印模块未加载成功!请检查无误后重启程序!");
		messageBox(1, sErrTips);
		return;
	}

	SRecordData stData = m_mapRecordData.value(sRecordId);

	//已经打印 进行二次提示
	if (stData.bIsPrint)
	{
		QString sTips = QString::fromLocal8Bit("该记录已经打印!是否再次打印?");
		int nRet = messageBox(3, sTips);
		if (QMessageBox::Yes != nRet)
		{
			return;
		}
	}

	char szErrMsg[256] = { 0 };

	//修改标题与打印张数
	//m_lpSetPrintConfig(m_sPrintTitle.toLocal8Bit().data(), m_nPrintNum, szErrMsg);

	//创建打印格式
	QList<QStringList> dlistToPrint;
	createPrintFormat(dlistToPrint, stData);
	//拼接打印字段
	QString sPrint;
	sPrint.append(dlistToPrint.at(0).at(0) + "%" + dlistToPrint.at(0).at(1));
	if (dlistToPrint.count() > 1)
	{
		for (int i = 1; i < dlistToPrint.count(); i++)
		{
			sPrint.append("," + dlistToPrint.at(i).at(0) + "%" + dlistToPrint.at(i).at(1));
		}
	}

	m_lpPrintLabel(sPrint.toLocal8Bit().data(), szErrMsg);

	//打印成功
	QString sErrMsg = QString::fromLocal8Bit(szErrMsg);
	if (sErrMsg.isEmpty())
	{
		//更新字段
		QString sErrMsg;
		bool bRet = CSqlOperPub::instance().updatePrintState(sRecordId, sErrMsg);
		//成功
		if (bRet)
		{
			SExecLog logInfo;
			logInfo.m_nAlarmLevel = enLogTypeRun;
			logInfo.m_sObject = QString::fromLocal8Bit("打印模块");
			logInfo.m_sLogDesc = QString::fromLocal8Bit("出厂记录 编号:") + sRecordId + QString::fromLocal8Bit(" 打印成功!");
			CLogOper::instance().addLogMsg("MainWindow", logInfo);

			//重新加载列表
			loadData();
		}
		else
		{
			SExecLog logInfo;
			logInfo.m_nAlarmLevel = enLogTypeAlarm;
			logInfo.m_sObject = QString::fromLocal8Bit("打印模块");
			logInfo.m_sLogDesc = QString::fromLocal8Bit("出厂记录 编号:") + sRecordId + QString::fromLocal8Bit(" 打印成功!但写入数据库失败!");
			CLogOper::instance().addLogMsg("MainWindow", logInfo);
		}
	}
	else
	{
		SExecLog logInfo;
		logInfo.m_nAlarmLevel = enLogTypeError;
		logInfo.m_sObject = QString::fromLocal8Bit("打印模块");
		logInfo.m_sLogDesc = QString::fromLocal8Bit("出厂记录 编号:") + sRecordId + QString::fromLocal8Bit("打印失败!错误原因: ") + sErrMsg;
		CLogOper::instance().addLogMsg("MainWindow", logInfo);
	}
}

/**
* @brief slotSelectRecord 查询记录
* @param
*/
void PoundListPrint::slotSelectRecord()
{
	m_qStartTime = ui.dateTimeEditStartTime->dateTime();
	m_qEndTime = ui.dateTimeEditEndTime->dateTime();
	m_sCarOrCargoCode = ui.lineEditCarOrCargoCode->text();
	m_sViewCardCode = ui.lineEditViewCardCode->text();
	m_nTimeType = ui.comboBox->currentData().toInt();

	//合法性判断
	bool bIsValid = judgeError();
	if (!bIsValid)
	{
		return;
	}

	//查询加载数据
	loadData();
}

/**
* @brief slotPrintPoundList 打印磅单
* @param
*/
void PoundListPrint::slotPrintPoundList()
{
	QPushButton *pOperBtn = (QPushButton *)sender();
	QString sReocrdId = pOperBtn->property("recordId").toString();

	//打印
	printRecord(sReocrdId);
}
